<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

  </head>

  <body>

  </body>
  <script>
    /* 
练习二：将数组中所有的元素用-进行分割，拼接成一个字符串
 */
    var arr = ['孙悟空', '猪八戒', '沙和尚', '唐僧'];
    var str = '';
    for (let index = 0; index < arr.length; index++) {
      if (index == arr.length - 1) {
        str += arr[index];
        break;
      } else {
        str += arr[index] + '-';
      }
    }
    console.log(str)
  </script>

</html>